﻿using System.Diagnostics;
using System.IO;
using iPud;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;

namespace iDev
{
    public class Program
    {
        public static void Main(string[] args)
        {
            SysUpdate.Run();
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            //var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
            //var pathToContentRoot = Path.GetDirectoryName(pathToExe);


            return WebHost.CreateDefaultBuilder(args)
                   .ConfigureAppConfiguration((hostingContext, config) =>
                   {
                       var env = hostingContext.HostingEnvironment;
                       config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
                       config.AddEnvironmentVariables();
                   })
                   .ConfigureLogging((hostingContext, logging) =>
                   {
                       var env = hostingContext.HostingEnvironment;
                       logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                       logging.AddNLog();
                       logging.AddConsole();
                       logging.AddDebug();
                   })
                   //.UseContentRoot(pathToContentRoot)
                   .UseDefaultServiceProvider(options => options.ValidateScopes = false)
                   .UseStartup<Startup>();
        }
    }
}
